#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project ：python_learning 
@File ：timer.py
@IDE  ：PyCharm 
@Author ：李涵彬
@Date ：2024/6/4 下午3:27 
"""

import time


def timer(func):
	def wrapper(*args, **kwargs):
		# start the timer
		start_time = time.time()
		# call the decorated function
		result = func(*args, **kwargs)
		# remeasure the time
		end_time = time.time()
		# compute the elapsed time and print it
		execution_time = end_time - start_time
		print(f"Execution time: {execution_time} seconds")
		# return the result of the decorated function execution
		return result

	# return reference to the wrapper function
	return wrapper


# Sample function 1
@timer
def connect() -> None:
	print('Connecting...')
	time.sleep(2)
	print('Connected!')


# Sample function 2
@timer
def fifty_million_loops() -> None:
	fifty_million: int = int(5e7)

	print('Looping...')
	for _ in range(fifty_million):
		pass

	print('Done looping!')


def main() -> None:
	fifty_million_loops()
	connect()


if __name__ == '__main__':
	main()
